// TOWN SCRIPT
//    Town 2: Sage's Hut (zanta's domain)

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 2, 0 = Zanta dead, activate portal now...
// 2, 1 = Zanta started talking

begintownscript;

variables;

short choice, lz;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(1);
	add_range_to_group(6, 10, 1); // group 1001

	// only one will be facing party
	set_name(6, "Lagoth Zanta");
	set_char_dialogue_pic(6, 537, 0);
	set_name(10, "Lagoth Zanta");
	set_char_dialogue_pic(10, 537, 0);

	// balance things...
	// remove some friends (potentially up to 2)
	if (get_flag(101, 0) <= 20) {
		erase_char(7);
		if (get_flag(101, 0) <= 12) {
			erase_char(9);
		}
	}
	// pick Lagoth Zanta to use, level him
	lz = 6;
	if (get_flag(101, 0) <= 16) {
		lz = 10;
		erase_char(6);
		relocate_character(10, 18, 22);
	}
	else {
		erase_char(10);
	}
	if (get_flag(101, 0) <= 10) {
		set_level(lz, 20); // third his level
	}
	else if (get_flag(101, 0) <= 24) {
		set_level(lz, 40); // third off
	}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	if (get_flag(2, 0) == 0) {
		message_dialog("The portal does not seem to be working right now.", "");
	}
	else {
		block_entry(1);
		reset_dialog_preset_options(3);
		choice = run_dialog(1);
		if (choice == 2) {
			set_flag(50, 1, TRUE);
			toggle_quest(0, 0);
			// set variable town entries (or reset them)
			set_flag(100, 0, 0);
			set_flag(100, 1, 15);
			set_flag(100, 2, 14);
			// take away staff
			message_dialog("As you step into the portal, you feel the staff slip out of your hands.",
				"It disappears into thin air with a little crackle of energy.");
			take_item(450);
			// teleport
			teleport_party(40, 24, 0);
		}
	}
break;
